faApp.controller('SimuNdyjCtrl',['$scope','simuService','simuNdyjService','$location','$controller','$routeParams','$filter',function($scope,simuService,simuNdyjService,$location,$controller,$routeParams,$filter) {   
   
	$controller('BaseCtrl', {$scope: $scope}); 
  $scope.id = $routeParams.id;
  $scope.formData = {id:$scope.id};
  $scope.item = {};
  $scope.jj = {};
  $scope.list = [];
  $scope.loading = true; 
  simuService.query({id:$scope.id}).then(function(json){
    $scope.jj = json.detail;
    json.detail.ndyjbJson = App.filterSimuJson(json.detail.ndyjbJson) || "{}";
    $scope.list = angular.fromJson(json.detail.ndyjbJson);
    if ($scope.list.length != undefined)$scope.list = {};
    $scope.list["1"] = $scope.list["1"] || {"ndyjsjz":"2014年"};
    $scope.list["2"] = $scope.list["2"] || {"ndyjsjz":"2013年"};
    $scope.list["3"] = $scope.list["3"] || {"ndyjsjz":"2012年"};
    $scope.list["4"] = $scope.list["4"] || {"ndyjsjz":"2011年"};
    $scope.list["5"] = $scope.list["5"] || {"ndyjsjz":"2010年"};
    $scope.list["6"] = $scope.list["6"] || {"ndyjsjz":"2009年"};
    $scope.list["7"] = $scope.list["7"] || {"ndyjsjz":"2008年"};
    $scope.formData.jjbm = $scope.jj.jjbm;
    $scope.edit(1);
    $scope.item.createBy = $scope.jj.createBy;
  }); 

  $scope.edit = function(v){
    $scope.itemIndex = v;
    $scope.item = $scope.list[v];
  };


  $scope.save = function(deleteFlag){ 
    $scope.jj.ndyjbJson = angular.toJson($scope.list);
    $scope.formData.ndyjbJson = angular.toJson($scope.list);
    simuNdyjService.edit($scope.formData).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $scope.addAlert("操作成功");
        $scope.item = {};
        $scope.itemIndex = undefined;
      }
    });
  };
 
}]);
